define(['jquery', 'bootstrap', 'backend', 'table', 'form','fast'], function ($, undefined, Backend, Table, Form,Fast) {
    var Controller = {
        index: function () {
          // 初始化表格参数配置
          Table.api.init({
            extend: {
                    index_url: 'resource/index/index',
                    add_url: 'resource/index/add',
                    edit_url: 'resource/index/edit',
                    del_url: 'resource/index/del',
                    multi_url: 'resource/index/multi',
                    table: 'adviser',
                }
            });

            var table = $('#table');
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                columns: [
                    [{
                        checkbox: true
                    },
                    {
                        field: 'id',
                        title: __('Id'),
                        operate: false
                    },
                    {
                        field: 'title',
                        title: __('标题'),
                    },
                    {
                        field: 'type.name',
                        title: __('身份类型'),
                        formatter: Table.api.formatter.label
                    },
                    {field: 'status', title: __('Status'), operate: false, formatter: Table.api.formatter.status},
                    {
                        field: 'operate',
                        title: __('Operate'),
                        table: table,
                        events: Table.api.events.operate,
                        formatter: Table.api.formatter.operate
                    }]
                ]
            });
            Table.api.bindevent(table);
            $(document).on('click', '.btn-addb', function () {
                Fast.api.ajax({
                    url: 'resource/index/addb',
                    loading:false,
                    success: function (result) {
                        if (result.code == 1) {
                            const data = result.data;

                            Fast.api.layer.open({
                                title:'选择身份类型',
                                area: '540px',
                                btn: [data[0].name,data[1].name,data[2].name,data[3].name,data[4].name,data[5].name],
                                yes:function(index){
                                    const typeId = data[0].id;
                                    Fast.api.open($.fn.bootstrapTable.defaults.extend.add_url + '?type_id=' + typeId, __('添加'));
                                }, 
                                btn2:function(index){
                                    const typeId = data[1].id;
                                    Fast.api.open($.fn.bootstrapTable.defaults.extend.add_url + '?type_id=' + typeId, __('添加'));
                                },
                                btn3:function(index){
                                    const typeId = data[2].id;
                                    Fast.api.open($.fn.bootstrapTable.defaults.extend.add_url + '?type_id=' + typeId, __('添加'));
                                },
                                btn4:function(index){
                                    const typeId = data[3].id;
                                    Fast.api.open($.fn.bootstrapTable.defaults.extend.add_url + '?type_id=' + typeId, __('添加'));
                                },
                                btn5:function(index){
                                    const typeId = data[4].id;
                                    Fast.api.open($.fn.bootstrapTable.defaults.extend.add_url + '?type_id=' + typeId, __('添加'));
                                },
                                btn6:function(index){
                                    const typeId = data[5].id;
                                    Fast.api.open($.fn.bootstrapTable.defaults.extend.add_url + '?type_id=' + typeId, __('添加'));
                                },
                                
                            })
                        } 
                    }
                });
            });
                
                
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($('form[role=form]'));
            }
        }
    };
    return Controller;
});